import { PRICE_BAND_OPTIONS } from '@/constant/goods'
import { IOptionClass } from '@/hooks/useGetClassIds'
import { IProDevSeason } from '@/hooks/useGetProDevSeason'
import { TwoDateVerify } from '@/utils/validator'
export const useFormBase = ({
  isEdit,
  ProDevSeason,
  DICTDATA,
  handleYearChange,
  classIdOptions,
  updateSalesPrice,
}: {
  isEdit: boolean
  ProDevSeason: IOptionItem[]
  DICTDATA: IDICTDATAType
  handleYearChange: (_: number, info: IProDevSeason) => void
  classIdOptions: IOptionClass[]
  updateSalesPrice: number
}): IItemArray[] => {
  return [
    {
      name: 'seasonId',
      label: '开发季',
      type: 'Select',
      option: ProDevSeason,
      placeholder: '请选择开发季',
      rules: [
        {
          required: true,
          message: '请选择开发季',
        },
      ],
      config: {
        optionFilterProp: 'label',
        onChange: handleYearChange,
      },
      hidden: isEdit,
    },
    {
      name: 'year',
      label: '年份',
      type: 'DatePicker',
      placeholder: '请选择开发季',
      rules: [
        {
          required: true,
          message: '请选择开发季',
        },
      ],
      config: {
        disabled: true,
        format: 'YYYY',
      },
      hidden: isEdit,
    },
    {
      name: 'classPath',
      label: '款式分类',
      type: 'Cascader',
      placeholder: '请选择款式分类',
      option: classIdOptions,
      config: {
        changeOnSelect: true,
        fieldNames: { label: 'className', value: 'classConfigId', children: 'childrenList' },
      },
      rules: [
        {
          required: true,
          message: '请选择款式分类',
        },
      ],
    },
    {
      name: 'seasonCode',
      label: '适销季节',
      type: 'Select',
      option: DICTDATA.sales_season,
      placeholder: '请选择适销季节',
      rules: [
        {
          required: true,
          message: '请选择适销季节',
        },
      ],
      config: {
        optionFilterProp: 'label',
      },
    },
    {
      name: 'releaseSeasonDate',
      label: '上市日期',
      type: 'DatePicker',
      placeholder: '请选择上市日期',
      rules: [
        {
          required: true,
          message: '请选择上市日期',
        },
        ({ getFieldValue }: any) => ({
          validator: (_: any, value: any) =>
            TwoDateVerify(_, value, getFieldValue('releaseSeasonDate'), getFieldValue('overSeasonDate')),
        }),
      ],
    },
    {
      name: 'overSeasonDate',
      label: '过季日期',
      type: 'DatePicker',
      placeholder: '请选择过季日期',
      rules: [
        {
          required: true,
          message: '请选择过季日期',
        },
        ({ getFieldValue }: any) => ({
          validator: (_: any, value: any) =>
            TwoDateVerify(
              _,
              value,
              getFieldValue('releaseSeasonDate'),
              getFieldValue('overSeasonDate'),
              '过季日期需要大于上市日期',
            ),
        }),
      ],
    },
    {
      name: 'planRate',
      label: '企划毛利率',
      type: 'InputNumber',
      placeholder: '请输入企划毛利率',
      rules: [
        {
          required: true,
          message: '请输入企划毛利率',
        },
      ],
      config: {
        addonAfter: '%',
        precision: 2,
      },
    },
    {
      name: 'profitRateLowerLimit',
      label: '毛利率下限',
      type: 'InputNumber',
      placeholder: '请输入毛利率下限',
      rules: [
        {
          required: true,
          message: '请输入毛利率下限',
        },
      ],
      config: {
        addonAfter: '%',
        precision: 2,
      },
    },
    {
      name: 'originSalePrice',
      label: '吊牌价',
      type: 'InputNumber',
      placeholder: '请输入吊牌价',
      rules: [
        {
          required: true,
          message: '请输入吊牌价',
        },
      ],
      config: {
        disabled: isEdit,
        precision: 2,
        min: 0,
      },
    },
    {
      name: 'updateSalesPrice',
      label: '吊牌价（修正）',
      type: 'InputNumber',
      placeholder: '请输入修正后的吊牌价',
      hidden: !isEdit,
      config: {
        precision: 2,
        min: 0,
      },
    },
    {
      name: 'updateReason',
      label: '修正原因',
      type: 'Input',
      placeholder: '请输入修正原因',
      rules:
        updateSalesPrice && updateSalesPrice >= 0
          ? [
              {
                required: true,
                message: '请输入修正原因',
              },
            ]
          : [
              {
                required: false,
              },
            ],
      config: {
        showCount: true,
        maxLength: 50,
      },
      hidden: !isEdit,
    },
    {
      name: 'priceTagCode',
      label: '价格带',
      type: 'Select',
      option: PRICE_BAND_OPTIONS,
      placeholder: '请选择价格带',
      hidden: false,
      rules: [
        {
          required: true,
          message: '请选择价格带',
        },
      ],
      config: {
        showSearch: true,
        filterOption: true,
        optionFilterProp: 'label',
      },
    },
    {
      name: 'priceProperty',
      label: '价格属性',
      type: 'Select',
      option: DICTDATA.sales_type,
      placeholder: '请选择价格属性',
      rules: [
        {
          required: true,
          message: '请选择价格属性',
        },
      ],
      config: {
        optionFilterProp: 'label',
      },
    },
    {
      name: 'priceAuth',
      label: '定价权限',
      type: 'Select',
      option: DICTDATA.pricing_auth,
      placeholder: '请选择定价权限',
      config: {
        optionFilterProp: 'label',
      },
    },
    {
      name: 'skcPlanNum',
      label: '企划SKC数量',
      type: 'InputNumber',
      placeholder: '请输入企划SKC数量',
      rules: [
        {
          required: true,
          message: '请输入企划SKC数量',
        },
      ],
      config: {
        precision: 0,
        min: 1,
      },
    },
    {
      name: 'devLocation',
      label: '开发定位',
      type: 'Select',
      option: DICTDATA.dev_location,
      placeholder: '请选择开发定位',
      config: {
        optionFilterProp: 'label',
      },
      rules: [
        {
          required: true,
          message: '请输入开发定位',
        },
      ],
    },
    {
      name: 'seasonGroup',
      label: '季节分组',
      type: 'Select',
      option: DICTDATA.season_classify,
      placeholder: '请选择季节分组',
      config: {
        optionFilterProp: 'label',
      },
      rules: [
        {
          required: true,
          message: '请输入季节分组',
        },
      ],
    },
    {
      name: 'productLevel',
      label: '商品等级',
      type: 'Select',
      option: DICTDATA.product_level,
      placeholder: '请选择商品等级',
      rules: [
        {
          required: true,
          message: '请选择商品等级',
        },
      ],
      config: {
        optionFilterProp: 'label',
      },
    },
    {
      name: 'suitAgeGroup',
      label: '适销年龄段',
      type: 'Select',
      option: DICTDATA.age_group,
      placeholder: '请选择适销年龄段',
      config: {
        optionFilterProp: 'label',
      },
    },
    // {
    //   name: 'designerName',
    //   label: '设计师/买手',
    //   type: 'Input',
    //   placeholder: '请输入设计师/买手',
    // },
    {
      name: 'productDesc',
      label: '商品描述',
      type: 'TextArea',
      placeholder: '请输入商品描述',
      config: {
        showCount: true,
        maxLength: 200,
      },
    },
  ]
}
